#ifndef TSP_SOLVER
#define TSP_SOLVER

#include <fstream>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <utility>
#include "CImg.h"
#include "main.hpp"

using namespace cimg_library;

using namespace std;

typedef struct Point
{
    int x;
    int y;
    Point(int _x=0,int _y=0):x(_x),y(_y){}
    bool operator == (const Point & value) const{
        return x==value.x&&y==value.y;
    }

    bool operator < (const Point & value) const{
        return x<value.x || (x==value.x && y<value.y);
    }
}Point;

#define dist(a,b) sqrtf((a.x-b.x)*(a.x-b.x)+(b.y-a.y)*(b.y-a.y))

const unsigned char red[3] = {255,0,0};
const unsigned char blue[3] = {0,0,255};

const int padding=5;
const int margin =2;

const int maxHeight = 500;
const int maxWidth = 500;
struct solution{
    vector<int> solve;
    int cost;
};

class TSP_solver
{
private:
    map<int, Point> pointMap;

    vector<double> costChange;

    vector<int> solve;
    int max_x;
    int max_y;

    void inputData(const char* datasetFile);

    void solveWithGreedy();

    void solveWithLocalsearch(int radius);

    void solveWithFile();

    void solveWithGenaration();

    void variation(vector<int>& solve);

    int solveConflictForSolution(solution& left,solution& right, int startPoint,int endPoint,int cityCount);

    int getTotalCost(vector<int> solve);
public:
    TSP_solver(const char* datasetFile);
    
    void showPoint();

    void showSolve();

    void showSolving(int speed);
};


#endif